package com.angus.modules.content.controller.work;

import com.angus.common.core.web.controller.BaseController;
import com.angus.common.core.web.domain.AjaxResult;
import com.angus.common.security.utils.SecurityUtils;
import com.angus.modules.content.dto.QueryBaseDto;
import com.angus.modules.content.service.SysFinanceService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/front/commission")
public class MyCommissionController extends BaseController {
    @Resource // 订单
    private SysFinanceService sysFinanceService;

    @GetMapping("/getList")
    public AjaxResult getList(QueryBaseDto dto, @RequestParam Map<String, Object> extendParams) {
        if (dto.getSearchExtend() == null) {
            dto.setSearchExtend(new HashMap<>());
        }
        dto.getSearchExtend().put("userId", SecurityUtils.getUserId());
        // 遍历所有参数，筛选出以 "searchExtend." 开头的参数
        extendParams.forEach((key, value) -> {
            if (key.startsWith("searchExtend.")) {
                // 截取前缀，如 "searchExtend.payMethod" → "payMethod"
                String mapKey = key.substring("searchExtend.".length());
                dto.getSearchExtend().put(mapKey, value);
            }
        });
        return AjaxResult.success(sysFinanceService.getOrderCommissionList(dto));
    }
}
